<!--
  Copyright © 2015 Cask Data, Inc.

  Licensed under the Apache License, Version 2.0 (the "License"); you may not
  use this file except in compliance with the License. You may obtain a copy of
  the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  License for the specific language governing permissions and limitations under
  the License.
-->

<fieldset ng-disabled="disabled">
  <div class="schema-container" ng-if="fields === 'GROK'">
    <div class="schema-inner">
      <label class="control-label">Pattern</label>
      <input type="text" class="form-control" ng-model="grok['pattern']" />
    </div>
  </div>

  <div class="schema-container" ng-if="fields === 'SHOW' || fields === 'GROK'" >
    <div class="text-danger" ng-if="error">
      {{ error }}
    </div>
    <div ng-if="properties.length > 0">
      <fieldset ng-disabled="disableEdit">
        <table class="table">
          <thead>
            <th>
              <label class="control-label">Name</label>
            </th>
            <th>
              <label class="control-label">Type</label>
            </th>
            <th>
              <label class="control-label">Null</label>
            </th>
            <th></th>
          </thead>
          <tbody infinite-scroll="loadNextSetOfRows()" infinite-scroll-disabled="properties.length <= limitedToView">
            <tr ng-repeat="property in properties | limitTo: limitedToView track by $index" ng-keypress="enter($event, $index)" ng-click="emptyRowClick(property, $index)">
              <td class="name" ng-if="!property.empty" ng-class="{'active-cell': activeCell === true}">
                <input
                    ng-focus="activeCell = true"
                    ng-blur="activeCell = false"
                    type="text"
                    class="form-control"
                    ng-model="property.name"
                    placeholder="name"
                    my-focus-watch="property.newField"
                    ng-disabled="property.readonly"/>
              </td>
              <td class="type" ng-if="!property.empty" ng-class="{'active-cell': activeCell === true}" >
                <div class="select-wrapper">
                  <select ng-model="property.type"
                      class="form-control col-xs-4"
                      ng-disabled="property.readonly"
                      ng-options="option as option for option in options"
                      ng-focus="activeCell = true"
                      ng-blur="activeCell = false"></select>
                </div>
              </td>
              <td class="text-center nullable" ng-if="!property.empty" ng-class="{'active-cell': activeCell === true}">
                <input type="checkbox"
                  ng-disabled="property.readonly"
                  ng-model="property.nullable"
                  ng-focus="activeCell = true"
                  ng-blur="activeCell = false" />
              </td>
              <td class="text-center trash" ng-if="!property.empty">
                <button href="" class="btn" ng-click="removeProperty(property)" ng-disabled="property.readonly">
                  <span class="fa fa-fw fa-trash"> </span>
                </button>
              </td>

              <td class="name" ng-if="property.empty"></td>
              <td class="type" ng-if="property.empty"></td>
              <td class="nullable" ng-if="property.empty"></td>
              <td class="trash" ng-if="property.empty"></td>
            </tr>
          </tbody>
        </table>
      </fieldset>
    </div>

  </div>

  <div class="schema-container" ng-if="fields === 'AVRO'">
    <div class="schema-inner">
      <textarea cask-json-edit="avro['schema']" class="form-control avro"></textarea>
    </div>
  </div>

  <div class="schema-container" ng-if="fields === 'NOTHING'">
    <div class="schema-inner">
      <div class="well well-lg text-center">
        <h4>No Editable Schema</h4>
      </div>
    </div>
  </div>

  <a class="sr-only" id="schema-export-link" href="{{url}}" download="{{exportFileName}}.json">Export</a>

</fieldset>
